package com.wanho.qz103.hrsaas.sys.dao.impl;

import com.wanho.qz103.hrsaas.commons.annontations.Repository;
import com.wanho.qz103.hrsaas.commons.dao.impl.BaseDAOImpl;
import com.wanho.qz103.hrsaas.commons.exception.DAOException;
import com.wanho.qz103.hrsaas.commons.exception.DataAccessException;
import com.wanho.qz103.hrsaas.sys.dao.EmployeeDAO;
import com.wanho.qz103.hrsaas.sys.pojos.Employee;
import com.wanho.qz103.hrsaas.sys.pojos.User;

import java.util.List;

@Repository
public class EmployeeDAOImpl extends BaseDAOImpl<Employee> implements EmployeeDAO {
    @Override
    public boolean insertBatch(List<Employee> employeeList) throws DAOException {
        try {
            // 因为 员工表为主表  用户基本信息表外键指向该主表
            String sql = "insert into sys_employees_detail(userid,username,mobile) VALUES(?,?,?)" ;
            Object[][] paramAy = new Object[employeeList.size()][3] ;
            for (int i = 0; i < employeeList.size(); i++) {
                Employee employee = employeeList.get(i);
                paramAy[i][0] =employee.getUserId() ;
                paramAy[i][1] = employee.getUsername();
                paramAy[i][2] = employee.getMobile() ;
            }
            return jdbcTemplate.insertBatch(sql,paramAy);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw new DAOException("批量插入用户表数据异常！！！") ;
        }
    }

    @Override
    protected String deleteSQL() {
        return null;
    }

    @Override
    protected String insertSQL() {
        return null;
    }

    @Override
    protected String updateSQL() {
        return "UPDATE sys_employees_detail \n" +
                "SET age = #{age},\n" +
                "archivingOrganization = #{archivingOrganization},\n" +
                "areThereAnyMajorMedicalHistories = #{areThereAnyMajorMedicalHistories},\n" +
                "bankCardNumber = #{bankCardNumber},\n" +
                "birthday = #{birthday},\n" +
                "bloodType = #{bloodType},\n" +
                "certificateOfAcademicDegree = #{certificateOfAcademicDegree},\n" +
                "constellation = #{constellation},\n" +
                "contactTheMobilePhone = #{contactTheMobilePhone},\n" +
                "dateOfBirth = #{dateOfBirth},\n" +
                "dateOfResidencePermit = #{dateOfResidencePermit},\n" +
                "departmentName = #{departmentName},\n" +
                "doChildrenHaveCommercialInsurance = #{doChildrenHaveCommercialInsurance},\n" +
                "domicile = #{domicile},\n" +
                "educationalType = #{educationalType},\n" +
                "emergencyContact = #{emergencyContact},\n" +
                "emergencyContactNumber = #{emergencyContactNumber},\n" +
                "englishName = #{englishName},\n" +
                "enrolmentTime = #{enrolmentTime},\n" +
                "graduateSchool = #{graduateSchool},\n" +
                "graduationCertificate = #{graduationCertificate},\n" +
                "graduationTime = #{graduationTime},\n" +
                "homeCompany = #{homeCompany},\n" +
                "idCardPhotoBack = #{idCardPhotoBack},\n" +
                "idCardPhotoPositive = #{idCardPhotoPositive},\n" +
                "idNumber = #{idNumber},\n" +
                "isThereAnyCompetitionRestriction = #{isThereAnyCompetitionRestriction},\n" +
                "isThereAnyViolationOfLawOrDiscipline = #{isThereAnyViolationOfLawOrDiscipline},\n" +
                "major = #{major},\n" +
                "maritalStatus = #{maritalStatus},\n" +
                "mobile = #{mobile},\n" +
                "nation = #{nation},\n" +
                "nationalArea = #{nationalArea},\n" +
                "nativePlace = #{nativePlace},\n" +
                "openingBank = #{openingBank},\n" +
                "passportNo = #{passportNo},\n" +
                "personalMailbox = #{personalMailbox},\n" +
                "placeOfResidence = #{placeOfResidence},\n" +
                "politicalOutlook = #{politicalOutlook},\n" +
                "postalAddress = #{postalAddress},\n" +
                "proofOfDepartureOfFormerCompany = #{proofOfDepartureOfFormerCompany},\n" +
                "providentFundAccount = #{providentFundAccount},\n" +
                "qq = #{qq},\n" +
                "remarks = #{remarks},\n" +
                "residenceCardCity = #{residenceCardCity},\n" +
                "residencePermitDeadline = #{residencePermitDeadline},\n" +
                "resume = #{resume},\n" +
                "sex = #{sex},\n" +
                "socialSecurityComputerNumber = #{socialSecurityComputerNumber},\n" +
                "staffPhoto = #{staffPhoto},\n" +
                "stateOfChildren = #{stateOfChildren},\n" +
                "theHighestDegreeOfEducation = #{theHighestDegreeOfEducation},\n" +
                "timeOfEntry = #{timeOfEntry},\n" +
                "timeToJoinTheParty = #{timeToJoinTheParty},\n" +
                "title = #{title},\n" +
                "username = #{username},\n" +
                "wechat = #{wechat},\n" +
                "zodiac = #{zodiac},\n" +
                "companyId = #{companyId}\n" +
                "\n" +
                "WHERE\n" +
                "\tuserId = #{userId}";
    }

    @Override
    protected String selectByIdSQL() {
        return "SELECT userId,\n" +
                "       age,\n" +
                "       archivingOrganization,\n" +
                "       areThereAnyMajorMedicalHistories,\n" +
                "       bankCardNumber,\n" +
                "       birthday,\n" +
                "       bloodType,\n" +
                "       certificateOfAcademicDegree,\n" +
                "       constellation,\n" +
                "       contactTheMobilePhone,\n" +
                "       dateOfBirth,\n" +
                "       dateOfResidencePermit,\n" +
                "       departmentName,\n" +
                "       doChildrenHaveCommercialInsurance,\n" +
                "       domicile,\n" +
                "       educationalType,\n" +
                "       emergencyContact,\n" +
                "       emergencyContactNumber,\n" +
                "       englishName,\n" +
                "       enrolmentTime,\n" +
                "       graduateSchool,\n" +
                "       graduationCertificate,\n" +
                "       graduationTime,\n" +
                "       homeCompany,\n" +
                "       idCardPhotoBack,\n" +
                "       idCardPhotoPositive,\n" +
                "       idNumber,\n" +
                "       isThereAnyCompetitionRestriction,\n" +
                "       isThereAnyViolationOfLawOrDiscipline,\n" +
                "       major,\n" +
                "       maritalStatus,\n" +
                "       mobile,\n" +
                "       nation,\n" +
                "       nationalArea,\n" +
                "       nativePlace,\n" +
                "       openingBank,\n" +
                "       passportNo,\n" +
                "       personalMailbox,\n" +
                "       placeOfResidence,\n" +
                "       politicalOutlook,\n" +
                "       postalAddress,\n" +
                "       proofOfDepartureOfFormerCompany,\n" +
                "       providentFundAccount,\n" +
                "       qq,\n" +
                "       remarks,\n" +
                "       residenceCardCity,\n" +
                "       residencePermitDeadline,\n" +
                "       resume,\n" +
                "       sex,\n" +
                "       socialSecurityComputerNumber,\n" +
                "       staffPhoto,\n" +
                "       stateOfChildren,\n" +
                "       theHighestDegreeOfEducation,\n" +
                "       timeOfEntry,\n" +
                "       timeToJoinTheParty,\n" +
                "       title,\n" +
                "       username,\n" +
                "       wechat,\n" +
                "       zodiac,\n" +
                "       companyId\n" +
                "FROM sys_employees_detail where userId=#{userId}";
    }


}
